package com.yanqu.road.server.logic.activity.condition.zfb;

import com.yanqu.road.entity.activity.ActivityConditionInfo;
import com.yanqu.road.entity.activity.ActivityInfo;
import com.yanqu.road.entity.enums.eGamePlayerEventType;
import com.yanqu.road.server.gameplayer.GamePlayer;
import com.yanqu.road.server.gameplayer.module.task.TaskModule;
import com.yanqu.road.server.logic.activity.BaseActivityData;
import com.yanqu.road.server.logic.activity.condition.BaseActivityCondition;
import com.yanqu.road.utils.date.DateHelper;
import com.yanqu.road.utils.string.StringUtils;

import java.math.BigInteger;

public class ZfbFollowUpCondition extends BaseActivityCondition {

    public ZfbFollowUpCondition(ActivityInfo activityInfo, ActivityConditionInfo activityConditionInfo, BaseActivityData baseActivityData) {
        super(activityInfo, activityConditionInfo, baseActivityData);
    }

    @Override
    protected void player_BoardLevelHandle(Object object) {
        int val = (int)object;
        int todayZeroTime = DateHelper.getTodayZeroTime();
        if(StringUtils.isNullOrEmpty(getParam())){
            setValue(BigInteger.valueOf(val));
            setParam(String.valueOf(todayZeroTime));
        }else {
            int lastDayZero = Integer.parseInt(getParam());
            if(lastDayZero != todayZeroTime){
                setParam(String.valueOf(todayZeroTime));
                setValue(getValue().add(BigInteger.valueOf(val)));
            }
        }
    }

    @Override
    public void addTrigger(GamePlayer player) {
        player.getModule(TaskModule.class).getGameEvent().addListener(eGamePlayerEventType.ZfbFollowUp.getValue(), handle);
    }

    @Override
    public void removeTrigger(GamePlayer player) {
        player.getModule(TaskModule.class).getGameEvent().removeListener(eGamePlayerEventType.ZfbFollowUp.getValue(), handle);
    }

    @Override
    public boolean isCompleted(GamePlayer player) {
        if(getValue().compareTo(activityConditionInfo.getParamList().get(3)) >= 0){
            return true;
        }
        return false;
    }
}
